package org.come.Jpanel;

import cn.hutool.core.thread.ThreadUtil;
import com.tool.btn.RoleMsgBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.come.bean.Role_bean;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.AnalysisString;
import org.come.until.CutButtonImage;

import javax.swing.*;
import java.awt.*;
import java.math.BigDecimal;



public class RoleMsgJpanel extends JPanel {
	private BigDecimal id;
	private String role;
	private JLabel labTx;
	private JLabel labname;
	private JLabel lablvl;
	private JLabel labchenwei;
	private JLabel labgang;
	private RoleMsgBtn btnzudui;
	private RoleMsgBtn btnhaoyou;
	private RoleMsgBtn btnjiaoyi;
	private RoleMsgBtn labgive;
	private RoleMsgBtn labpk;
	private RoleMsgBtn lbasuod;
	private RoleMsgBtn labjiaotan;
	private ImageIcon icon;
	private ImageIcon iconx;
	private ImageIcon icont;

	public RoleMsgJpanel() {
		if("水墨UI".equals(MyIsif.getStyle())) {
			this.setPreferredSize(new Dimension(160, 185));
			this.setLayout(null);
			this.setBackground(new Color(0, 0, 0, 0));
			(this.labTx = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labTx);
			(this.labname = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labname);
			(this.lablvl = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.lablvl);
			(this.labchenwei = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labchenwei);
			(this.labgang = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labgang);
			(this.btnzudui = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "组队", 1)).setBounds(22, 18, 40, 40);
			this.add((Component)this.btnzudui);
			(this.btnjiaoyi = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "交易", 2)).setBounds(22, 18, 40, 40);
			this.add((Component)this.btnjiaoyi);
			(this.btnhaoyou = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "好友", 3)).setBounds(22, 18, 40, 40);
			this.add((Component)this.btnhaoyou);
			(this.labgive = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "给与", 4)).setBounds(22, 18, 40, 40);
			this.add((Component)this.labgive);
			(this.labpk = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "切磋", 5)).setBounds(22, 18, 40, 40);
			this.add((Component)this.labpk);
			(this.lbasuod = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "锁定", 20)).setBounds(22, 18, 40, 40);
			this.add((Component)this.lbasuod);
			(this.labjiaotan = new RoleMsgBtn("skin/8100226/newbutton/B30.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "交谈", 7)).setBounds(22, 18, 40, 40);
			this.add((Component)this.labjiaotan);

		}else{

			this.setPreferredSize(new Dimension(160, 185));
			this.setLayout(null);
			this.setBackground(new Color(0, 0, 0, 0));
			(this.labTx = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labTx);
			(this.labname = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labname);
			(this.lablvl = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.lablvl);
			(this.labchenwei = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labchenwei);
			(this.labgang = new JLabel()).setBounds(22, 18, 40, 40);
			this.add((Component)this.labgang);
			(this.btnzudui = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "组队", 1)).setBounds(22, 18, 40, 40);
			this.add((Component)this.btnzudui);
			(this.btnjiaoyi = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "交易", 2)).setBounds(22, 18, 40, 40);
			this.add((Component)this.btnjiaoyi);
			(this.btnhaoyou = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "好友", 3)).setBounds(22, 18, 40, 40);
			this.add((Component)this.btnhaoyou);
			(this.labgive = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "给与", 4)).setBounds(22, 18, 40, 40);
			this.add((Component)this.labgive);
			(this.labpk = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "切磋", 5)).setBounds(22, 18, 40, 40);
			this.add((Component)this.labpk);
			(this.lbasuod = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "锁定", 20)).setBounds(22, 18, 40, 40);
			this.add((Component)this.lbasuod);
			(this.labjiaotan = new RoleMsgBtn("inkImg/hongmu/1/ss531.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT, "交谈", 7)).setBounds(22, 18, 40, 40);
			this.add((Component)this.labjiaotan);
		}
	}

	public void show(final BigDecimal id, final String name) {
		this.id = id;
		this.role = name;
		try {
			RoleMsgBtn.role_bean = null;
			String msg = Agreement.getAgreement().searcahChatRoleIdAgreement(id.toString());
			SendMessageUntil.toServer(msg);
			ThreadUtil.execAsync(new Thread(()->{
				try {
					Role_bean role_bean = RoleMsgBtn.role_bean;
					while (role_bean == null){
						Thread.sleep(100L);
						role_bean = RoleMsgBtn.role_bean;
					}

					this.labchenwei.setForeground(Color.green);
					this.labchenwei.setText(role_bean.getTitle());
					this.labchenwei.setFont(new Font("宋体", 0, 13));
					this.labgang.setForeground(Color.white);
					this.labgang.setText(role_bean.getGangname());
					this.labgang.setFont(new Font("宋体", 0, 13));
					this.lablvl.setForeground(Color.white);

					this.lablvl.setText(AnalysisString.lvl(role_bean.getGrade()) + "级");
					this.lablvl.setFont(new Font("宋体", 0, 13));
					this.labname.setText(name);
					this.labname.setForeground(UIUtils.getcolor(role_bean.getTurnAround()));
					this.labname.setFont(new Font("宋体", 0, 13));
					this.labTx.setIcon((Icon) CutButtonImage.getImage("img/head/s" + role_bean.getSpeciesId() + ".png", 40, 40));

				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}));

		}
		catch (Exception ex) {}
	}

	@Override
	protected void paintComponent(final Graphics g) {
		super.paintComponent(g);
		if("水墨UI".equals(MyIsif.getStyle())) {

			this.labTx.setBounds(11, 15, 40, 40);
			this.labname.setBounds(61, 5, 120, 15);
			this.lablvl.setBounds(61, 20, 120, 15);
			this.labgang.setBounds(61, 35, 120, 15);
			this.labchenwei.setBounds(61, 50, 120, 15);
			this.btnzudui.setBounds(114, 75, 37, 17);
			this.btnjiaoyi.setBounds(114, 97, 34, 17);
			this.btnhaoyou.setBounds(114, 119, 34, 17);
			this.labgive.setBounds(114, 141, 34, 17);
			this.labpk.setBounds(114, 163, 34, 17);
			this.lbasuod.setBounds(64, 97, 34, 17);
			this.labjiaotan.setBounds(64, 75, 34, 17);
			if (this.icon == null) {
				this.icon = new ImageIcon("skin/8100226/newbutton/s600.png");
			}
			if (this.iconx == null) {
				this.iconx = new ImageIcon("skin/8100226/newbutton/s602.png");
			}
			g.drawImage(this.icon.getImage(), 0, 0, null);
			g.drawImage(this.iconx.getImage(), 5, 9, 52, 52, null);
			if (this.icont == null) {
				this.icont = new ImageIcon("skin/8100226/newbutton/s601.png");
			}
			g.drawImage(this.icont.getImage(), 58, 70, 96, 115, null);
		}else{

			this.labTx.setBounds(11, 15, 40, 40);
			this.labname.setBounds(61, 5, 120, 15);
			this.lablvl.setBounds(61, 20, 120, 15);
			this.labgang.setBounds(61, 35, 120, 15);
			this.labchenwei.setBounds(61, 50, 120, 15);
			this.btnzudui.setBounds(114, 75, 37, 17);
			this.btnjiaoyi.setBounds(114, 97, 34, 17);
			this.btnhaoyou.setBounds(114, 119, 34, 17);
			this.labgive.setBounds(114, 141, 34, 17);
			this.labpk.setBounds(114, 163, 34, 17);
			this.lbasuod.setBounds(64, 97, 34, 17);
			this.labjiaotan.setBounds(64, 75, 34, 17);
			if (this.icon == null) {
				this.icon = new ImageIcon("skin/8100226/newbutton/s600h.png");
			}
			if (this.iconx == null) {
				this.iconx = new ImageIcon("skin/8100226/newbutton/s602h.png");
			}
			g.drawImage(this.icon.getImage(), 0, 0, null);
			g.drawImage(this.iconx.getImage(), 5, 9, 52, 52, null);
			if (this.icont == null) {
				this.icont = new ImageIcon("skin/8100226/newbutton/s601h.png");
			}
			g.drawImage(this.icont.getImage(), 58, 70, 96, 115, null);
		}
	}

	public BigDecimal getId() {
		return this.id;
	}

	public void setId(final BigDecimal id) {
		this.id = id;
	}

	public String getRole() {
		return this.role;
	}

	public void setRole(final String role) {
		this.role = role;
	}

	public RoleMsgBtn getLbasuod() {
		return this.lbasuod;
	}

	public void setLbasuod(final RoleMsgBtn lbasuod) {
		this.lbasuod = lbasuod;
	}

	public RoleMsgBtn getLabjiaotan() {
		return this.labjiaotan;
	}

	public void setLabjiaotan(final RoleMsgBtn labjiaotan) {
		this.labjiaotan = labjiaotan;
	}
}
